﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>数据账套</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>
</head>
<body>
    <span style="margin-top:15px;margin-left:15px">
        <xblock>
   
            <button class="layui-btn " onclick="saveData()"><i class="layui-icon"></i>保存</button>
            <button class="layui-btn " onclick="closeWin()"><i class="layui-icon">&#x1006;</i>取消</button>
      
        </xblock>
    </span>

    <div style="margin: 20px; border: 1px solid #dbdbdb;padding:15px">

        <form id="AddForm" class="layui-form layui-col-space5">

            <div class="layui-form-item">

                <label for="L_email" class="layui-form-label">
                    账套名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="customName" name="customName" required="" autocomplete="off" class="layui-input">
                    <input type="hidden" id="id" name="Id">
                </div>
                @*<label for="L_email" class="layui-form-label">
                    账套编码
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="DbCode" name="DbCode" required="" autocomplete="off" class="layui-input">
                </div>*@
            </div>
            <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">
                    IP地址
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="serverIp" name="serverIp" required="" autocomplete="off" class="layui-input">
                </div>
                <label for="L_email" class="layui-form-label">
                    数据库名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="baseName" name="baseName" required="" autocomplete="off" class="layui-input">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">
                    登录账号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="logid" name="logid" required="" autocomplete="off" class="layui-input">
                </div>
                <label for="L_email" class="layui-form-label">
                    登录密码
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="pwd" name="pwd" required="" autocomplete="off" class="layui-input">

                </div>
            </div>


            <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">
                    是否默认
                </label>
                <div class="layui-input-inline">
                    <select name="isDefault" id="isDefault"  ></select>
                </div>
                <label for="L_email" class="layui-form-label">
                    是否启用
                </label>
                <div class="layui-input-inline">
                    <select name="status" id="status" ></select>
                </div>

            </div>
        </form>

    </div>
</body>
</html>
<script type="text/javascript">
    $(function () {
        var dataId = getUrlVariable("dataId");
        DictionaryDropDown("ct", "isDefault", "");
        DictionaryDropDown("ct", "status", "");
        if (dataId != "0") {
            $("input[ name='Id']").val(dataId);
            loadData(dataId);
        }

    });

    /**
    保存数据
    **/ 
    function saveData() {
        $.ajax({
            url: "../System/SaveBaseData",
            data: { datas: JSON.stringify(FormToJson("AddForm")) },
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    var id = $("input[ name='id']").val();
                    var msg = "信息修改成功";
                    if (id == "0" || id == "") {
                        msg = "信息添加成功";
                    }
                    layer.alert(msg, { icon: 6 }, function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                } else {
                    layer.msg(data.Message);
                }
            }
        });
    }

    //加载数据信息
    function loadData(dataId) {
        $.ajax({
            url: "../System/getCustomBaseByCode",
            type: "post",
            data: { dataId: dataId },
            success: function (data) {
                if (data.Result) {

                    $.each(data.Data[0], function (name, value) {
                        if (name == "isDefault" || name == "status") {
                            $("#" + name + "  option[value='" + value + "'] ").attr("selected", true)
                        } else {
                            $("input[ name='" + name + "']").val(value);
                        }
                    
                    });
                  //  $("#parValue").html(data.Data[0]["parValue"]);
                  
                
                }
            }
        });

    }
</script>